﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YhmOA.IDAL
{
    /// <summary>
    /// 通用泛型DAL接口
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface ITDal<T> where T : class
    {
        /// <summary>
        /// 取得实体集合
        /// </summary>
        /// <param name="conditions">条件</param>
        /// <param name="pageSize">页面大小</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="orderByStr">排序</param>
        /// <param name="recCount">总数量</param>
        /// <returns>实体集合</returns>
        List<T> GetList(string conditions, int pageSize, int pageIndex, string orderByStr, out int recCount);

        /// <summary>
        /// 通用查询
        /// </summary>
        /// <param name="whereStr">查询条件</param>
        /// <param name="searchColumn">要查询的列</param>
        /// <param name="searchStr">搜索关键字</param>
        /// <param name="pageIndex">当前第几页</param>
        /// <param name="pageSize">每页的大小</param>
        /// <param name="orderColumn">排序的列</param>
        /// <param name="order">排序的方向</param>
        List<T> SearchTable(
            String whereStr,
            String searchColumn,
            String searchStr,
            Int32 pageIndex,
            Int32 pageSize,
            String orderColumn,
            String order,
            out Int32 count);

        /// <summary>
        /// 根据ID得到实体
        /// </summary>
        /// <param name="id">id</param>
        /// <returns>实体</returns>
        T GetModelByID(long id);

        /// <summary>
        /// 根据条件和排序取得单个实体
        /// </summary>
        /// <param name="conditions">条件</param>
        /// <param name="orderByStr">排序</param>
        /// <returns>单个实体</returns>
        T GetSingle(string conditions, string orderByStr);

        /// <summary>
        /// 添加一个实体
        /// </summary>
        /// <param name="info">实体</param>
        /// <returns>操作是否成功</returns>
        bool Add(T info);

        /// <summary>
        /// 添加实体集合
        /// </summary>
        /// <param name="list">实体集合</param>
        /// <returns>操作是否成功</returns>
        bool AddRange(List<T> list);

        /// <summary>
        /// 更新一个实体
        /// </summary>
        /// <param name="info">实体</param>
        /// <returns>操作是否成功</returns>
        bool Update(T info, long id);

        /// <summary>
        /// 根据ID和SET子句键值对更新
        /// 方法：从Dynamiclinq中得到查询SQL语句，然后从SQL语句中生成更新SQL语句，然后ExecuteStoreCommand得到的更新SQL语句
        /// </summary>
        /// <param name="kv">KeyValuePair<string, string></param>
        /// <param name="id">条件</param>
        /// <returns>操作是否成功</returns>
        bool Update(KeyValuePair<string, string> kv, long id);

        /// <summary>
        /// 根据条件和SET子句键值对更新
        /// 方法：从Dynamiclinq中得到查询SQL语句，然后从SQL语句中生成更新SQL语句，然后ExecuteStoreCommand得到的更新SQL语句
        /// </summary>
        /// <param name="kv">KeyValuePair<string, string></param>
        /// <param name="conditions">条件</param>
        /// <returns>操作是否成功</returns>
        bool Update(KeyValuePair<string, string> kv, string conditions);

        /// <summary>
        /// 根据条件和SET子句键值对集合更新
        /// 方法：从Dynamiclinq中得到查询SQL语句，然后从SQL语句中生成更新SQL语句，然后ExecuteStoreCommand得到的更新SQL语句
        /// </summary>
        /// <param name="kvList">List<KeyValuePair<string, string>></param>
        /// <param name="conditions">条件</param>
        /// <returns>操作是否成功</returns>
        bool Update(List<KeyValuePair<string, string>> kvList, string conditions);

        /// <summary>
        /// 根据条件和SET子句更新
        /// 方法：从Dynamiclinq中得到查询SQL语句，然后从SQL语句中生成更新SQL语句，然后ExecuteStoreCommand得到的更新SQL语句
        /// </summary>
        /// <param name="kvStr">SET子句</param>
        /// <param name="conditions">条件</param>
        /// <returns>操作是否成功</returns>
        bool Update(string kvStr, string conditions);

        /// <summary>
        /// 删除一个实体
        /// </summary>
        /// <param name="id">id</param>
        /// <returns>操作是否成功</returns>
        bool DeleteByID(long id);

        /// <summary>
        /// 根据ids批量删除实体
        /// </summary>
        /// <param name="ids">ids,ids格式：id_id_</param>
        /// <returns>操作是否成功</returns>
        bool DeleteByIDS(string ids);

        /// <summary>
        /// 根据条件删除
        /// </summary>
        /// <param name="conditions">条件</param>
        /// <returns>操作是否成功</returns>
        bool Delete(string conditions);
    }
}
